<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2020/8/28
 * Time: 13:47
 * 首页
 */
namespace app\shop\controller;
use think\Db;
class First extends Base
{
    public function index(){
        $banner = Db::table('up_banner')
            ->where('banner_status',1)
            ->where('banner_cate',1)
            ->order('banner_sort desc')
            ->field('banner_id,banner_thumb,banner_type,banner_link')
            ->select();
        $this->assign('banner',$banner);
//
        $fugai = $this->fugai();
        $this->assign('data',$fugai['data']);
        $this->assign('data2',$fugai['data2']);
        $this->assign('dis',$fugai['dis']);
        $yunli = $this->yunli();
        $this->assign('name',$yunli['name']);
        $this->assign('value',$yunli['value']);
        $this->assign('colors',$yunli['colors']);
//
        $areas = [
            0 => '全部' ,
            1 => '华东' ,
            2 => '华南' ,
            3 => '华中' ,
            4 => '华北' ,
            5 => '西北' ,
            6 => '西南' ,
            7 => '东北' ,
            8 => '台港澳'
        ];
        $liang = [];
        $where = [];
        $where['order_qy_user'] = session('user_id');
        foreach ($areas as $k => $v){
            if($k == 0){
                $liang[$k] = Db::table('up_order')
                    ->where($where)
                    ->count();
            }else{
                $liang[$k] = Db::table('up_order')
                    ->where($where)
                    ->where('order_quyu',$v)
                    ->count();
            }
        }
        $this->assign('areas',$areas);
        $this->assign('liang',$liang);
        return $this->fetch();
    }
    public function fugai()
    {
        $dis = 0;
        $data = Db::table('up_u_user')->where('user_role',2)
            ->field('user_company_name name,user_match_lon,user_match_lat')
            ->select();
        $data2 = array();
        if($data){
            $dis = 1;
            foreach ($data as $k=>$v){
                $data[$k]['value'] = 50;
                $data2[$v['name']] = [$v['user_match_lon'],$v['user_match_lat']];
            }
        }
        $data = json_encode($data);
        $data2 = json_encode($data2);
        $res = [
            'dis' => $dis ,
            'data' => $data ,
            'data2' => $data2 ,
        ];
        return $res;
    }
    public function yunli()
    {
        $name = [];
        $value = [];
        $colors = [];
        $where = [];
        $where['is_del'] = 1;
        $where['is_status'] = 1;
        $res = Db::table('up_car_cx')->where($where)->field('cx_name')->select();
        foreach ($res as $key=>&$vo){
            $cx_name = $vo['cx_name'] ;
            $map['cx_id'] = array('like',"%$cx_name%");
            $num = Db::table('up_order')->where($map)->count();
            $vo['num'] = $num;
            //
            $name[] = $vo['cx_name'];
            $value[] = $num;
            $colors[] = '#59ADFE';
        }
        $res = [
            'name' => json_encode($name) ,
            'value' => json_encode($value),
            'colors' => json_encode($colors),
        ];
        return $res;
    }
    public function getWuliuTypes(){
        $where = [];
        $where['order_qy_user'] = session('user_id');
        if(isset($_POST['quyu']) && $_POST['quyu'] != '全部'){
            $where['order_quyu'] = $_POST['quyu'];
        }
        $a = Db::table('up_order')->where($where)->group('order_fb_ymr')->column('order_fb_ymr');
        sort($a);
        $res = array();
        foreach ($a as $key=>$vo){
            $aa = Db::table('up_order')
                ->where($where)
                ->where('order_fb_ymr',$vo)
                ->count();
            $res[] = $aa;
        }
        $result['date'] = $a;
        $result['value'] = $res;
        return json(['msg' => $result]);
    }
    public function banner_detail()
    {
        $id = input('param.id');
        $banner = Db::table('up_banner')
            ->where('banner_id',$id)
            ->find();
        $this->assign('data',$banner);
        return $this->fetch();
    }
}
